package com.cloud.system.api.mapper;

import com.cloud.system.api.entity.DicRegion;
import com.cloud.system.common.driver.SimpleInlangDriver;
import com.cloud.system.common.result.SelectItem;
import com.cloud.system.common.utils.BaseMapperHelper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @program: quokka-server
 * @description: ${description}
 * @author: sl
 * @create: 2019-07-31 11:40
 **/
public interface DicRegionMapper  extends BaseMapperHelper<DicRegion> {
    @Select("select region_code as value, region_name as label, region_level as level,senior_region_code as seniorId from dic_region where region_level < 5")
    @Results({ @Result(property = "value", column = "value", javaType = String.class),
            @Result(property = "label", column = "label", javaType = String.class),
            @Result(property = "seniorId", column = "seniorId", javaType = String.class),
            @Result(property = "regionLevel", column = "regionLevel", javaType = Integer.class),})
    List<SelectItem> selectAllAddress();

    @Select("SELECT p.region_code AS senior_region_code,c.region_code AS region_code FROM dic_region p LEFT JOIN dic_region c ON c.senior_region_code = p.region_code WHERE p.region_code = #{regionCode} AND c.region_name LIKE #{regionName}")
    @Results({ @Result(property = "regionCode", column = "region_code", javaType = String.class),
            @Result(property = "seniorRegionCode", column = "senior_region_code", javaType = String.class)})
    List<DicRegion> selectAddressByRegionCode(@Param("regionCode") String regionCode,@Param("regionName") String regionName);



}
